package adger.me.yili.bean;

import org.xutils.DbManager;
import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;
import org.xutils.ex.DbException;

import java.util.List;

/**
 * Created by heyue on 16/1/30.
 */
@Table(name = "OrdersBeanTable")
public class OrdersBeanTable {
    @Column(name = "error")
    private int error;
    @Column(name = "status")
    private String status;
    @Column(name = "group_id",isId = true)
    private int group_id;
    @Column(name = "group_no")
    private int group_no;
    @Column(name = "group_name")
    private String group_name;
    @Column(name = "claim_day")
    private String claim_day;
    @Column(name = "count")
    private int count;

    private List<OrdersEntity> orders;

    public String getClaim_day() {
        return claim_day;
    }

    public void setClaim_day(String claim_day) {
        this.claim_day = claim_day;
    }

    public void setError(int error) {
        this.error = error;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public void setGroup_id(int group_id) {
        this.group_id = group_id;
    }

    public void setGroup_no(int group_no) {
        this.group_no = group_no;
    }

    public void setGroup_name(String group_name) {
        this.group_name = group_name;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public void setOrders(List<OrdersEntity> orders) {
        this.orders = orders;
    }

    public int getError() {
        return error;
    }

    public String getStatus() {
        return status;
    }

    public int getGroup_id() {
        return group_id;
    }

    public int getGroup_no() {
        return group_no;
    }

    public String getGroup_name() {
        return group_name;
    }

    public int getCount() {
        return count;
    }

    public List<OrdersEntity> getOrders() {
        return orders;
    }
    public List<OrdersEntity> getChildren(DbManager db) throws DbException {
        return db.selector(OrdersEntity.class).where("parentId", "=", this.group_id).findAll();
//            return db.findById(OrdersBeanTable.class, this.partent_id);
    }
    @Table(name = "OrdersEntity", onCreated = "CREATE UNIQUE INDEX autoId ON OrdersEntity(autoId)")
    public static class OrdersEntity {
        @Column(name = "autoId", isId = true)
        private int autoId;

        @Column(name = "id")
        private String id;
        @Column(name = "user")
        private String user;
        @Column(name = "user_sn")
        private String user_sn;
        @Column(name = "deliver")
        private int deliver;
        @Column(name = "telephone")
        private String telephone;
        @Column(name = "address")
        private String address;
        @Column(name = "memo")
        private String memo;
        @Column(name = "claimed")
        private int claimed;
        @Column(name = "charge")
        private float charge;
        @Column(name = "confirmed")
        private int confirmed;

        @Column(name = "partent_id" /*, property = "UNIQUE"//如果是一对一加上唯一约束*/)
        private int partent_id;// 外键表id  OrdersTable的id

        private List<OrderLinesEntity> order_lines;

        public int getPartent_id() {
            return partent_id;
        }

        public void setPartent_id(int partent_id) {
            this.partent_id = partent_id;
        }

        public int getAutoId() {
            return autoId;
        }

        public void setAutoId(int autoId) {
            this.autoId = autoId;
        }

        public void setId(String id) {
            this.id = id;
        }

        public void setUser(String user) {
            this.user = user;
        }

        public void setUser_sn(String user_sn) {
            this.user_sn = user_sn;
        }

        public void setDeliver(int deliver) {
            this.deliver = deliver;
        }

        public void setTelephone(String telephone) {
            this.telephone = telephone;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public void setMemo(String memo) {
            this.memo = memo;
        }

        public void setClaimed(int claimed) {
            this.claimed = claimed;
        }

        public float getCharge() {
            return charge;
        }

        public void setCharge(float charge) {
            this.charge = charge;
        }

        public void setConfirmed(int confirmed) {
            this.confirmed = confirmed;
        }

        public void setOrder_lines(List<OrderLinesEntity> order_lines) {
            this.order_lines = order_lines;
        }

        public String getId() {
            return id;
        }

        public String getUser() {
            return user;
        }

        public String getUser_sn() {
            return user_sn;
        }

        public int getDeliver() {
            return deliver;
        }

        public String getTelephone() {
            return telephone;
        }

        public String getAddress() {
            return address;
        }

        public String getMemo() {
            return memo;
        }

        public int getClaimed() {
            return claimed;
        }


        public int getConfirmed() {
            return confirmed;
        }

        public List<OrderLinesEntity> getOrder_lines() {
            return order_lines;
        }

        public List<OrderLinesEntity> getChildren(DbManager db) throws DbException {
            return db.selector(OrderLinesEntity.class).where("parentId", "=", this.id).findAll();

//            return db.findById(OrdersBeanTable.class, this.partent_id);
        }
        @Table(name = "OrderLinesEntity")
        public static class OrderLinesEntity {
            @Column(name = "autoId", isId = true)
            private int autoId;
            @Column(name = "name")
            private String name;
            @Column(name = "price")
            private float price;
            @Column(name = "quantity")
            private int quantity;
            @Column(name = "unit")
            private String unit;
            @Column(name = "buy_unit")
            private String buy_unit;
            @Column(name = "weighable")
            private int weighable;
            @Column(name = "charge")
            private float charge;
            @Column(name = "id")
            private String id;

            public String getId() {
                return id;
            }

            public void setId(String id) {
                this.id = id;
            }

            @Column(name = "partent_id" /*, property = "UNIQUE"//如果是一对一加上唯一约束*/)
            private String partent_id;// 外键表id  OrdersTable的id


            public String getBuy_unit() {
                return buy_unit;
            }

            public void setBuy_unit(String buy_unit) {
                this.buy_unit = buy_unit;
            }

            public int getAutoId() {
                return autoId;
            }

            public void setAutoId(int autoId) {
                this.autoId = autoId;
            }

            public String getPartent_id() {
                return partent_id;
            }

            public void setPartent_id(String partent_id) {
                this.partent_id = partent_id;
            }

            public void setName(String name) {
                this.name = name;
            }

            public float getPrice() {
                return price;
            }

            public void setPrice(float price) {
                this.price = price;
            }

            public void setQuantity(int quantity) {
                this.quantity = quantity;
            }

            public void setUnit(String unit) {
                this.unit = unit;
            }

            public void setWeighable(int weighable) {
                this.weighable = weighable;
            }


            public String getName() {
                return name;
            }

            public float getCharge() {
                return charge;
            }

            public void setCharge(float charge) {
                this.charge = charge;
            }

            public int getQuantity() {
                return quantity;
            }

            public String getUnit() {
                return unit;
            }

            public int getWeighable() {
                return weighable;
            }



            public OrdersEntity getParent(DbManager db) throws DbException {
                return db.findById(OrdersEntity.class, this.partent_id);
            }
        }
    }
}
